home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4575 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.9 KB  |  50 lines

  1. Newsgroups: comp.lang.c++
  2. Path: ncrgw2.ncr.com!ncrhub6!daynews!falcon!news
  3. From: Dick Menninger <Dick.Menninger@DaytonOH.ATTGIS.COM>
  4. Subject: Re: Q: how to handle currency?
  5. X-Nntp-Posting-Host: 149.25.118.167
  6. Message-ID: <DM0qBx.CK7@falcon.daytonoh.attgis.com>
  7. Sender: news@falcon.daytonoh.attgis.com (News administrative Login)
  8. Reply-To: Dick.Menninger@DaytonOH.ATTGIS.COM (mennid)
  9. Organization: AT&T Global Information Solutions
  10. X-Newsreader: DiscussIT 2.5.1.3 for MS Windows [AT&T Software Products Division]
  11. References: <4e93he$ec@sun.cis.smu.edu>
  12. Date: Tue, 30 Jan 1996 23:52:45 GMT
  13.  
  14.  
  15. > ==========Damon Bowman, 1/25/96==========
  16.  
  17.  
  18. > Another beginner question:
  19.  
  20. > What data type is used for currency when you want "precision as
  21. > displayed?"  When using the float or double data types, you run into
  22. > the problem of imprecision.  In other words, I want to actually round
  23. > off my numbers when necessary to create real amounts of EXACTLY 47.23,
  24. > or whatever the case may be.
  25. > One of my books suggests that there is a method of doing this with
  26. > integers, but it does not go into any detail.
  27.  
  28. > Any assistance is appreciated.
  29.  
  30. If decimal works for the money, then 64-bit integers will
  31. do nicely, most likely, since you can get about 20 digits.
  32. Just have the value represent the smallest amount and
  33. then divide/mod by the right power of ten to get the parts.
  34. If you ever need more digits than 20, well they need a
  35. currency revaluation and they will not be using the right
  36. side of decimal point.  The exception might be some
  37. economic space game situations (or other games) where
  38. double precision floating point would work fine for a lot longer.
  39. You might need to use floating point for calculations
  40. even if 64-bit integers are fine for actual currency values.
  41. But if decimal does not work, then it will be trickier
  42. as there is, probably, a quaint collection of possibilities
  43. that are not expressed as decimal values.
  44.  
  45. Good Day
  46. Dick
  47. Dick.Menninger@DaytonOH.ATTGIS.COM
  48.  
  49.